package com.gzhryc.shared_device.oem.code.statistics.dao;

import com.gzhryc.jdbc.Conditions;
import com.gzhryc.jdbc.DateBranchTableDao;
import com.gzhryc.jdbc.Query;
import com.gzhryc.shared_device.oem.code.statistics.dao.db.PlaceDayStatistics;
import com.gzhryc.shared_device.oem.code.statistics.dao.models.PlaceSumMoneyData;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

public class PlaceDayStatisticsDao extends DateBranchTableDao<PlaceDayStatistics> {

    public PlaceDayStatisticsDao(String jdbcKey, Date date) {
        super(jdbcKey, date);
    }

    public List<PlaceSumMoneyData> sumGroupPlaceIdByConditions(Conditions conditions) throws SQLException {
        String sql = "SELECT place_id as placeId, sum(order_count) as orderCount" +
                ",sum(order_money) as orderMoney,sum(order_pay_money) as orderPayMoney" +
                ",sum(cancel_order_count) as cancelOrderCount" +
                ",sum(cancel_order_money) as cancelOrderMoney" +
                ",sum(history_cancel_order_count) as historyCancelOrderCount" +
                ",sum(history_cancel_order_money) as historyCancelOrderMoney" +
                ",sum(history_refund_order_count) as historyRefundOrderCount" +
                ",sum(history_refund_order_money) as historyRefundOrderMoney" +
                " FROM " + this.tableName;

        Query query = new Query(sql);
        query.appendSql(conditions.toSql(query.getParams(),true));
        query.appendSql(" GROUP BY place_id");

        return this.jdbcHelper.find(query,PlaceSumMoneyData.class);
    }
}
